package com.zlf.mapper;

import com.zlf.po.WalletTransaction;
import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;
import java.util.List;

@Mapper
public interface WalletTransactionMapper {
    @Insert("insert into wallettransation(createTime,fromWalletId,toWalletId,transactionAmount,transferId,isConfirmed) values(#{createTime},#{fromWalletId},#{toWalletId},#{transactionAmount},#{transferId},#{isConfirmed})")
    @Options(useGeneratedKeys = true,keyProperty = "transferId",keyColumn = "transferId")
    public int saveTransaction(WalletTransaction walletTransaction);

    @Select("select * from wallettransation where transferId=#{transferId} ")
    public WalletTransaction getTransactionById(Long transferId);
    @Select("select * from wallettransation where fromWalletId=#{WalletId} or toWalletId=#{WalletId} order by createTime")
    public List<WalletTransaction> listTransactionByWalletId(Long WalletId);
    @Select("select * from wallettransation where fromWalletId=#{fromWalletId} order by createTime")
    public List<WalletTransaction> listTransactionByFromWalletId(Long fromWalletId);
    @Select("select * from wallettransation where toWalletId=#{toWalletId} order by createTime")
    public List<WalletTransaction> listTransactionByToWalletId(Long toWalletId);
    @Select("select sum(transactionAmount) from wallettransation where fromWalletId=#{fromWalletId} AND wallettransation.toWalletId IS NOT NULL")
    public BigDecimal getConsumption(Long fromWalletId);
    @Update("update wallettransation set isConfirmed = true where transferId=#{transferId}")
    public void confirm(Long trandferId);

}
